/// @tags: DPonTree
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1e5 + 5;

struct Edge {
  int v, nxt;
} e[N << 1];

int n, e_cnt, k;
int f[N][21], s[N], heads[N], dep[N];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

inline void dfs1(int u, int fa) {
  for (int i = heads[u], v; i; i = e[i].nxt)
    if ((v = e[i].v) != fa) {
      dfs1(v, u);
      for (int j = 1; j <= k; ++j) f[u][j] += f[v][j - 1];
    }
}

inline void dfs2(int u, int fa) {
  for (int i = heads[u], v; i; i = e[i].nxt)
    if ((v = e[i].v) != fa) {
      for (int j = k; j >= 2; --j) f[v][j] -= f[v][j - 2];
      for (int j = 1; j <= k; ++j) f[v][j] += f[u][j - 1];
      dfs2(v, u);
    }
}

inline int main() {
  cin >> n >> k;
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  for (int i = 1; i <= n; ++i) cin >> s[i], f[i][0] = s[i];
  dep[1] = 1;
  dfs1(1, 1), dfs2(1, 1);
  for (int i = 1; i <= n; ++i) {
    int ans = 0;
    for (int j = 0; j <= k; ++j) ans += f[i][j];
    cout << ans << '\n';
  }
  return 0;
}
}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3047 [USACO12FEB] Nearby Cows G.in", "r", stdin);
  freopen("P3047 [USACO12FEB] Nearby Cows G.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
